package cn.fl.ref.fribaseinfo.controller;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hazelcast.util.CollectionUtil;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.condition.SysUlDatCfgQueryCondition;
import cmm.comm.facade.upload.dto.SysUlDatCfgDTO;
import cmm.comm.facade.upload.dto.SysUlDatCfgDtlDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysUsrApiService;
import cmm.user.facade.system.dto.SysUsrDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.capital.service.ICapPayeeInfoApiService;
import cn.fl.capital.vo.CapPayMaterialVo;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.ref.crbaseinfo.transform.CrBaseInfoVOTransform;
import cn.fl.ref.crbaseinfo.vo.CrBaseInfoVO;
import cn.fl.ref.fncpreabslim.service.IFncPreAbsLimService;
import cn.fl.ref.fncpreabslim.vo.FncPreAbsLimVO;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.service.IFundInsSimilarInfoService;
import cn.fl.ref.fribaseinfo.service.IFundRasInsLimService;
import cn.fl.ref.fribaseinfo.transform.BankAccInfoVOTransform;
import cn.fl.ref.fribaseinfo.transform.FriBaseFlowVOTransform;
import cn.fl.ref.fribaseinfo.transform.FriBaseInfoVOTransform;
import cn.fl.ref.fribaseinfo.transform.FundRasInsRlPsnVOTransform;
import cn.fl.ref.fribaseinfo.vo.BankAccInfoVO;
import cn.fl.ref.fribaseinfo.vo.FriBaseFlowVO;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.ref.fribaseinfo.vo.FundInsSimilarInfoVO;
import cn.fl.ref.fribaseinfo.vo.FundRasInsLimVO;
import cn.fl.ref.fribaseinfo.vo.FundRasInsRlPsnVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.upload.constant.UploadConstant;
import fl.customer.facade.customer.constant.CustomerConstant;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.ref.contract.constant.FncPrjContMainConstant;
import fl.ref.crbaseinfo.condition.CrBaseInfoQueryCondition;
import fl.ref.crbaseinfo.constant.CrBaseInfoConstant;
import fl.ref.crbaseinfo.dto.CrBaseInfoDTO;
import fl.ref.crbaseinfo.service.ICrBaseInfoApiService;
import fl.ref.fncpreabslim.dto.FncPreAbsLimDTO;
import fl.ref.fribaseinfo.condition.BankAccInfoQueryCondition;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.condition.FundRasInsLimQueryCondition;
import fl.ref.fribaseinfo.condition.FundRasInsRlPsnQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import fl.ref.fribaseinfo.dto.BankAccInfoDTO;
import fl.ref.fribaseinfo.dto.FriBaseFlowDTO;
import fl.ref.fribaseinfo.dto.FriBaseInfoDTO;
import fl.ref.fribaseinfo.service.IBankAccInfoApiService;
import fl.ref.fribaseinfo.service.IFundRasInsRlPsnApiService;

/**
 * @Description: 融资机构基础信息
 */
@Controller
@RequestMapping("/rfbase/fribaseinfo")
public class FriBaseInfoController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(FriBaseInfoController.class);

	@Autowired
	private IFriBaseInfoService friBaseInfoService;

	@Autowired
	private ICrBaseInfoApiService crBaseInfoApiService;
	/**
	 * 数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	/**
	 * 附件服务
	 */
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;

	/**
	 * 融资机构PRE-ABS
	 */
	@Autowired
	IFncPreAbsLimService fncPreAbsLimService;
	/**
	 * 银行帐号信息
	 */
	@Autowired
	private IBankAccInfoApiService bankAccInfoApiService;
	@Autowired
	private ISysUsrApiService sysUsrApiService;
	/**
	 * 资管机构相似度
	 */
	@Autowired
	private IFundInsSimilarInfoService fundInsSimilarInfoService;
	@Autowired
	private IFundRasInsLimService fundRasInsLimService;
	/**
	 * PrjBscInfo 服务层BEAN
	 */
	@Autowired
	private IPrjBscInfoService prjBscInfoService;//项目基础信息表
	@Autowired
	private IUploadApiService uploadApiService;
	/**
	 * 金融机构关联人员信息表 服务层BEAN
	 */
	@Autowired
	private IFundRasInsRlPsnApiService fundRasInsRlPsnApiService;
	
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET })
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		logger.info("加载融资机构基础信息列表页面.");
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friBaseInfoList");
		// 授信状态
		List<KeyValueVO> crStList = friBaseInfoService.getKvList(CrBaseInfoConstant.CR_BSC_INFO_CR_ST);
		view.addObject("crStList", crStList);
		// 融资机构类型
		List<KeyValueVO> insStsList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_STS);
		view.addObject("insStsList", insStsList);
		return view;
	}

	/**
	 * 到新增修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friBaseInfoAdd");
		String id = request.getParameter("id");
		view.addObject("id", id);
		// 融资机构类型
		List<KeyValueVO> insTypeList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_TYPE_CD);
		view.addObject("insTypeList", insTypeList);
		// 银行 账户类型
		List<KeyValueVO> pubVerPriCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.BANK_ACC_INFO_PUB_VER_PRI_CD);
		view.addObject("pubVerPriCdList", pubVerPriCdList);
		// 是否为ABS
		List<KeyValueVO> yesNoList = friBaseInfoService.searchYesNoKVList();
		List<KeyValueVO> list2 = friBaseInfoService.getKvList( DictionaryConstant.CODE_PRJ_TYPE_CD);
		view.addObject("prjTypCds", list2);
		view.addObject("yesNoList", yesNoList);
		// 还款方式
		List<KeyValueVO> list = friBaseInfoService.getKvList(FriBaseInfoConstant.INS_REPAY_TYPE_CD);
		view.addObject("insRepayTypeList", list);		
		return view;
	}
	
	@RequestMapping(value = "/getInsUseCd.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object getInsUseCd(HttpServletRequest request, HttpServletResponse response) {
		// 融资机构用途
		List<KeyValueVO> insUseCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_USE_CD);
		return insUseCdList;
	}
	
	@RequestMapping(value = "/getAccTypCd.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object getAccTypCd(HttpServletRequest request, HttpServletResponse response) {
		// 银行帐户用途
		List<KeyValueVO> list = friBaseInfoService.getKvList(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD);
		List<KeyValueVO> listn=new ArrayList<KeyValueVO>();
		//去除自有帐号
		for (int i = 0; i < list.size(); i++) {
			if (!list.get(i).getKey().equals(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_ZY)
					) {
				listn.add(list.get(i));
			}
		}

		return listn;
		
	}
	@RequestMapping(value = "/getAccTypCd2.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object getAccTypCd2(HttpServletRequest request, HttpServletResponse response) {
		// 银行帐户用途
		List<KeyValueVO> list = friBaseInfoService.getKvList(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD);
		List<KeyValueVO> listn=new ArrayList<KeyValueVO>();
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getKey().equals(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_ZY)
				||	list.get(i).getKey().equals(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_ZG)
				||list.get(i).getKey().equals(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_PRE)
					) {
				listn.add(list.get(i));
			}
		}

		return listn;
	}
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET })
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friBaseInfoDetail");
		String id = request.getParameter("id");
		String tabFlag = request.getParameter("tabFlag");
		view.addObject("id", id);
		view.addObject("tabFlag", tabFlag);
		return view;
	}

	/**
	 * 到修改帐户信息页面
	 */
	@RequestMapping(value = "/toAddBankPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddBankPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friBaseInfoAddBank");
		String id = request.getParameter("id");
		view.addObject("id", id);
		// 融资机构类型
		List<KeyValueVO> insTypeList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_TYPE_CD);
		view.addObject("insTypeList", insTypeList);
		// 银行 账户类型
		List<KeyValueVO> pubVerPriCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.BANK_ACC_INFO_PUB_VER_PRI_CD);
		view.addObject("pubVerPriCdList", pubVerPriCdList);
		// 是否为ABS
		List<KeyValueVO> yesNoList = friBaseInfoService.searchYesNoKVList();
		view.addObject("yesNoList", yesNoList);
		return view;
	}

	/**
	 * 初始化列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String fundRasInsNm = request.getParameter("fundRasInsNm");// 融资机构名称
		String insSts = request.getParameter("insSts");// 融资机构状态
		String stDt = request.getParameter("stDt");// 授信期限 开始时间
		String edDt = request.getParameter("edDt");// 授信期限 结束时间
		String crSt = request.getParameter("crSt"); // 授信状态
		String insUseCd = request.getParameter("insUseCd"); // 机构用途

		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		FriBaseInfoQueryCondition qc = new FriBaseInfoQueryCondition();
		if (StringUtils.isNotEmpty(fundRasInsNm)) {
			qc.setFundRasInsNm(fundRasInsNm);
		}
		if (StringUtils.isNotEmpty(insSts)) {
			qc.setInsSts(insSts);
		}
		if (StringUtils.isNotEmpty(stDt) && StringUtils.isNotEmpty(edDt)) {
			qc.setStDt(DateUtils.formatStringToDate(stDt, DateUtils.YYYY_MM_DD));
			qc.setEdDt(DateUtils.formatStringToDate(edDt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(crSt)) {
			qc.setCrSt(Integer.parseInt(crSt));
		}
		if (StringUtils.isNotEmpty(insUseCd)) {
			qc.setInsUseCd(insUseCd);
		}
		String insCode=request.getParameter("insCode");
		if (StringUtils.isNotEmpty(insCode)) {
			qc.setInsCode(insCode);
		}
		if (StringUtils.isNotEmpty(request.getParameter("isBa"))) {
			qc.setIsBa(request.getParameter("isBa"));
		}
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(qc);

		Pager pager = this.friBaseInfoService.searchListPage(page);
		List<FriBaseInfoDTO> list = (List<FriBaseInfoDTO>) pager.getResultList();
		List<FriBaseInfoVO> voList = FriBaseInfoVOTransform.toVOList(list);

		// 授信额度 实际使用额度 余额
		for (FriBaseInfoVO friBaseInfoVO : voList) {
			CrBaseInfoQueryCondition condition = new CrBaseInfoQueryCondition();
			condition.setCrStQ(CrBaseInfoConstant.CR_BSC_INFO_CR_ST_PASS);
			condition.setFncInsIdQ(friBaseInfoVO.getId());
			List<CrBaseInfoDTO> listDTO = crBaseInfoApiService.searchList(condition);
			List<CrBaseInfoVO> listVO = CrBaseInfoVOTransform.toVOList(listDTO);
			BigDecimal crBal = new BigDecimal(0);
			BigDecimal crLmt = new BigDecimal(0);
			for (CrBaseInfoVO crBaseInfoVO : listVO) {
				crBal = crBal.add(crBaseInfoVO.getCrBal());
				crLmt = crLmt.add(crBaseInfoVO.getCrLmt());
			}
			friBaseInfoVO.setCrBal(crBal);
			friBaseInfoVO.setCrLmt(crLmt);
			friBaseInfoVO.setUseLmt(crLmt.subtract(crBal));
		}

		ListPageVO<FriBaseInfoVO> listPage = new ListPageVO<FriBaseInfoVO>(voList, pager.getTotalCount());

		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String fundRasInsNm = request.getParameter("fundRasInsNm");// 融资机构名称
		String insAbb = request.getParameter("insAbb");// 机构缩写
		String insTypeCd = request.getParameter("insTypeCd");// 融资机构类型
		String attCd = request.getParameter("attCd");// 附件
		String rem = request.getParameter("rem");// 备注
		String isAbs = request.getParameter("isAbs");// 是否为ABS
		String bankArray = request.getParameter("bankArray"); // 银行帐号信息
		String insUseCd = request.getParameter("insUseCd");// 机构用途
		String isOutPay = request.getParameter("isOutPay");//是否外部机构投放
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");

		try {
			// 验证
			if (StringUtils.isEmpty(fundRasInsNm)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "融资机构名称不能为空!");
			}
			if (StringUtils.isEmpty(insAbb)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "机构缩写不能为空!");
			}
			if (friBaseInfoService.isInsAbbExist(null, insAbb)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_606, "机构缩写不能重复!");
			}

			FriBaseInfoVO entity = new FriBaseInfoVO();
			entity.setFundRasInsNm(fundRasInsNm);
			entity.setInsAbb(insAbb);
			entity.setInsCode(insAbb);
			entity.setInsTypeCd(insTypeCd);
			entity.setAttCd(attCd);
			entity.setRem(rem);
			entity.setIsAbs(Integer.valueOf(isAbs));
			entity.setInsUseCd(insUseCd);
			entity.setIsOutPay(isOutPay);
			entity.setZgText(request.getParameter("zgText"));
			if (StringUtils.isNotBlank(request.getParameter("insRepayType"))) {
				entity.setInsRepayType(Integer.valueOf(request.getParameter("insRepayType")));
				
			}
			if (StringUtils.isNotBlank(request.getParameter("topFinance"))) {
				entity.setTopFinance(Long.valueOf(request.getParameter("topFinance")));
				
			}
			// 银行帐号信息
			JSONArray bankJsonArray = JSONArray.parseArray(bankArray);
			List<BankAccInfoVO> bankAccInfoVOs = new ArrayList<>();
			if (bankJsonArray.size() > 0) {
				for (int i = 0; i < bankJsonArray.size(); i++) {
					BankAccInfoVO bankAccInfoVO = JSONObject.toJavaObject(bankJsonArray.getJSONObject(i), BankAccInfoVO.class);
					bankAccInfoVOs.add(bankAccInfoVO);
				}
			}
			if (friBaseInfoService.isAccNumExist(bankAccInfoVOs)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_606, "银行帐号不能重复!");
			}
			entity.setBankAccInfoVOs(bankAccInfoVOs);

			entity.setInsSts(FriBaseInfoConstant.FRI_BASE_INFO_INS_STS_PASS); // 机构状态 审核
			entity.setIsValid(BaseConstant.IS_YESNO_YES); // 有效
			entity.setIsDel(BaseConstant.IS_YESNO_NO); // 未删除
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId()); // 新增人
			entity.setCrtTm(new Date()); // 新增时间
			Long mainId = this.friBaseInfoService.add(entity);

			uploadAttchment(request, result, mainId);// 附件上传
			//添加资管机构限额
			JSONArray typeJsonArray = JSONArray.parseArray(request.getParameter("typeArray") );
	
			if (typeJsonArray.size() > 0) {
				for (int i = 0; i < typeJsonArray.size(); i++) {
					FundRasInsLimVO  vo = JSONObject.toJavaObject(typeJsonArray.getJSONObject(i), FundRasInsLimVO.class);
					vo.setInsId(mainId.toString());
					vo.setId(null);
					vo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
					
					fundRasInsLimService.add(vo);
				}
			}
			//add 初始化机构相似列表 by gengchunlan  20200209
			try {
				BaseLogUtils.info(logger, "addFundInsSimilarInfo", "addFundInsSimilarInfo@@mainId"+mainId , CurrentThreadContext.getCurrentUserName());
				//首先判断机构用途 机构用途需包含资管
				if(StringUtils.isNotEmpty(insUseCd)) {
					if(insUseCd.indexOf("2")>=0) {
				if(StringUtils.isNotEmpty(mainId)) {
					//新增本机构为1级别优先级
					FundInsSimilarInfoVO cvo=new FundInsSimilarInfoVO();
					cvo.setMainFundInsId(mainId);
					cvo.setFundRasInsId(mainId);
					cvo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
					cvo.setZgNum(1l);
					fundInsSimilarInfoService.add(cvo);
					//初始化机构相似的列表
					FundInsSimilarInfoVO svo=new FundInsSimilarInfoVO();
					svo.setMainFundInsId(mainId);
					svo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
					fundInsSimilarInfoService.insertSimilarByBatch(svo);
					//追加机构相似的列表
					FundInsSimilarInfoVO ssvo=new FundInsSimilarInfoVO();
					ssvo.setFundRasInsId(mainId);
					ssvo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
					fundInsSimilarInfoService.insertSimilarByAppend(ssvo);	
				}
					}
					
				}
			}catch(Exception e) {
				BaseLogUtils.error(logger, "addFundInsSimilarInfo", "新增数据失败,addFundInsSimilarInfo@@mainId"+mainId + e.getMessage(), CurrentThreadContext.getCurrentUserName());
			}
			//end by gengchunlan 20200209
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("新增成功!");
			BaseLogUtils.info(logger, "add", "新增数据 ,name[" + fundRasInsNm + "]. ID:" + mainId, CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败,name[" + fundRasInsNm + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "add", "新增数据失败,name[" + fundRasInsNm + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}


	/**
	 * 修改
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String fundRasInsNm = request.getParameter("fundRasInsNm");// 融资机构名称
		String insAbb = request.getParameter("insAbb");// 机构缩写
		String insTypeCd = request.getParameter("insTypeCd");// 融资机构类型
		String attCd = request.getParameter("attCd");// 附件
		String rem = request.getParameter("rem");// 备注
		String isAbs = request.getParameter("isAbs");// 是否为ABS
		String bankArray = request.getParameter("bankArray"); // 银行帐号信息
		String insUseCd = request.getParameter("insUseCd");// 机构用途

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		try {
			// 验证
			if (StringUtils.isEmpty(fundRasInsNm)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "融资机构名称不能为空!");
			}
			if (StringUtils.isEmpty(insAbb)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "机构缩写不能为空!");
			}
			if (friBaseInfoService.isInsAbbExist(Long.valueOf(id), insAbb)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_606, "机构缩写不能重复!");
			}
			FriBaseInfoVO entity = new FriBaseInfoVO();
			entity.setId(Long.valueOf(id));
			entity.setFundRasInsNm(fundRasInsNm);
			entity.setInsAbb(insAbb);
//			entity.setInsCode(insAbb);
			entity.setInsTypeCd(insTypeCd);
			entity.setAttCd(attCd);
			entity.setRem(rem);
			entity.setIsAbs(Integer.valueOf(isAbs));
			entity.setInsUseCd(insUseCd);
			entity.setZgText(request.getParameter("zgText"));
			// 银行帐号信息
			JSONArray bankJsonArray = JSONArray.parseArray(bankArray);
			List<BankAccInfoVO> bankAccInfoVOs = new ArrayList<>();
			if (bankJsonArray.size() > 0) {
				for (int i = 0; i < bankJsonArray.size(); i++) {
					BankAccInfoVO bankAccInfoVO = JSONObject.toJavaObject(bankJsonArray.getJSONObject(i), BankAccInfoVO.class);
					bankAccInfoVOs.add(bankAccInfoVO);
				}
			}
			if (friBaseInfoService.isAccNumExist(bankAccInfoVOs)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_606, "银行帐号不能重复!");
			}
			entity.setBankAccInfoVOs(bankAccInfoVOs);

			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId()); // 修改人
			entity.setMdfTm(new Date()); // 修改时间
			this.friBaseInfoService.modify(entity);
			
			BaseLogUtils.newServiceLogger("uploadAttchment开始").info();
			uploadAttchment(request, result, Long.valueOf(id));// 附件上传
			BaseLogUtils.newServiceLogger("uploadAttchment结束").info();
			
			BaseLogUtils.newServiceLogger("typeJsonArray："+JSON.toJSONString(request.getParameter("typeArray"))).info();
			//添加资管机构限额
			JSONArray typeJsonArray = JSONArray.parseArray(request.getParameter("typeArray") );
	
			BaseLogUtils.newServiceLogger("JSONArray.parseArray(request.getParameter(typeArray))结束,typeJsonArray:"+typeJsonArray).info();
			if (typeJsonArray != null && typeJsonArray.size() > 0) {
				for (int i = 0; i < typeJsonArray.size(); i++) {
					FundRasInsLimVO  vo = JSONObject.toJavaObject(typeJsonArray.getJSONObject(i), FundRasInsLimVO.class);
					vo.setInsId(id);
					vo.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
					if (vo.getId()!=null) {
						fundRasInsLimService.modify(vo);
					}else {
						fundRasInsLimService.add(vo);
					}
					
				}
			}
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("更新成功!");
			BaseLogUtils.info(logger, "modify", "修改数据,id[" + id + "].", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			ex.printStackTrace();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改数据失败,id[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			ex.printStackTrace();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误");
			BaseLogUtils.error(logger, "modify", "修改数据失败,id[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 作废 逻辑删除
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/remove.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object remove(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		try {
			FriBaseInfoVO entity = new FriBaseInfoVO();
			entity.setId(Long.valueOf(id));
			entity.setIsDel(BaseConstant.IS_YESNO_YES);
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId()); // 修改人
			entity.setMdfTm(new Date()); // 修改时间
			this.friBaseInfoService.modify(entity);
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("更新成功!");
			BaseLogUtils.info(logger, "modify", "修改数据,id[" + id + "].", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改数据失败,id[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误");
			BaseLogUtils.error(logger, "modify", "修改数据失败,id[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 得到一条记录
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功!");
		FriBaseInfoVO friBaseInfoVO = null;
		try {
			friBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			result.setData(friBaseInfoVO);
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误!");
			BaseLogUtils.error(logger, "getById", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 上传附件
	 * 
	 * @param request
	 * @param result
	 * @param id
	 */
	private void uploadAttchment(HttpServletRequest request, DataResultVO result, Long id) {
		String attchmnt = request.getParameter("docArray");
		if (StringUtils.isNotEmpty(attchmnt)) {
			// 上传解析
			try {
				String cfgCd = PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_CFGCD);
				String cfgDtlCd = PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_CFGDTLCD);
				String tabNm = PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_TABNM);
				String cfgOrgCd = PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_CFGORG);
				Boolean attchmntPass = this.sysUlFilesRecService.addAttchmnt(String.valueOf(id), attchmnt, cfgCd, cfgDtlCd, tabNm, "客户主要信息附件!", null,
						null, false, cfgOrgCd);
				if (null == attchmntPass || attchmntPass == false) {
					result.setInfo(result.getInfo() + "-附件上传失败!");
				}
			} catch (Exception e) {
				result.setInfo(result.getInfo() + "-附件上传失败!");
			}
		}
	}

	/**
	 * 审核流程
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/addFlowStart.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addFlowStart(HttpServletRequest request, HttpServletResponse response) {

		String id = request.getParameter("id");
		String procDefKey = request.getParameter("procDefKey");
		String procDefId = request.getParameter("procDefId");
		String procNo = request.getParameter("procNo");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if (StringUtils.isEmpty(id)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "addFlowStart", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			// 流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(FriBaseInfoConstant.REF_FLOW_S_H_FRI);
			flowStartParamsDTO.setProcDefKey(procDefKey);
			flowStartParamsDTO.setProcDefId(procDefId);
			flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setBusinessKey(id);
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);// 优先级,可以在界面定义
			flowStartParamsDTO.setBusinessType(FriBaseInfoConstant.FLOW_BUSINESS_TYP_FUND_RAS_INS_BASE_INFO);// 确认用不用
			flowStartParamsDTO.setModelTyp(FriBaseInfoConstant.FLOW_MODEL_TYP_FRI);// 需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm() + "、融资机构审核流程大字段参数未定!");
			DataResultDTO dataResultDTO = this.friBaseInfoService.addFlowStart(flowStartParamsDTO);
			if (!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if (null != dataResultDTO && null != dataResultDTO.getData()) {
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if (StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())) {
					result.setInfo("下一个节点操作人:" + flowStartedDTO.getNextOperUsrNames());
				} else {
					result.setInfo("流程发起成功");
				}
			}
			/*
			 * if(null != dataResultDTO.getInfo() && StringUtils.isNotEmpty(dataResultDTO.getInfo())){ StringBuffer info = new StringBuffer();
			 * info.append(result.getInfo()); info.append(SysLogConstant.LOG_FLOW_NEXT_TASK_OPERATOR); info.append(dataResultDTO.getInfo());//操作人
			 * result.setInfo(info.toString()); }
			 */
			 //获取融资机构账户信息，设置账户审核状态 audStsCd mainID 
			BankAccInfoQueryCondition bankAccInfoQC = new BankAccInfoQueryCondition();
			bankAccInfoQC.setFundRasInsId(Long.parseLong(id));//融资机构id
			List<BankAccInfoDTO> bankAccInfoDTOs=bankAccInfoApiService.searchList(bankAccInfoQC);
			for(BankAccInfoDTO acc :bankAccInfoDTOs){
				//账户 已保存  审核不通过 修改为审核中
				if(null!=acc.getAudStsCd() && !"".equals(acc.getAudStsCd().toString())){
					if("0".equals(acc.getAudStsCd().toString())|| "3".equals(acc.getAudStsCd().toString())){
						BankAccInfoDTO accDto=new BankAccInfoDTO ();
						accDto.setAudStsCd(Integer.parseInt(FriBaseInfoConstant.BANK_ACC_AUD_STS_IN));//设置状态
						accDto.setId(acc.getId());//id
						bankAccInfoApiService.modify(accDto);//更新数据库融资机构账户状态
					}
				}else{
					BankAccInfoDTO accDto=new BankAccInfoDTO ();
					accDto.setAudStsCd(Integer.parseInt(FriBaseInfoConstant.BANK_ACC_AUD_STS_IN));//设置状态
					accDto.setId(acc.getId());//id
					bankAccInfoApiService.modify(accDto);//更新数据库融资机构账户状态
				}
			}//end 设置账户审核状态
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "addFlowStart",
					"错误[BaseException],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" + e.getMessage(),
					CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addFlowStart",
					"错误[Exception],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" + e.getMessage(),
					CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		}
		return result;
	}
	/**
	 * 发起再融资机构账户审核流程
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/addFlowStartForAccount.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addFlowStartForAccount(HttpServletRequest request, HttpServletResponse response) {

		String id = request.getParameter("id");
		//String procDefKey = request.getParameter("procDefKey");
		//String procDefId = request.getParameter("procDefId");
		//String procNo = request.getParameter("procNo");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if (StringUtils.isEmpty(id)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "addFlowStartForAccount", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			// 流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(FriBaseInfoConstant.REF_FLOW_S_H_FRI);
			//flowStartParamsDTO.setProcDefKey(procDefKey);
			//flowStartParamsDTO.setProcDefId(procDefId);
			//flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setBusinessKey(id);
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);// 优先级,可以在界面定义
			//flowStartParamsDTO.setBusinessType(FriBaseInfoConstant.FLOW_BUSINESS_TYP_FUND_RAS_INS_BASE_INFO);// 确认用不用
			flowStartParamsDTO.setModelTyp(FriBaseInfoConstant.BANK_ACC_FLOW_MODEL_TYP);// 需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm() + "、融资机构账户审核大字段参数未定!");
			DataResultDTO dataResultDTO = this.friBaseInfoService.addFlowStartForAccount(flowStartParamsDTO);
			if (!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if (null != dataResultDTO && null != dataResultDTO.getData()) {
				/*FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if (StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())) {
					result.setInfo("下一个节点操作人:" + flowStartedDTO.getNextOperUsrNames());
				} else {
					result.setInfo("流程发起成功");
				}*/
			}
			//更新数据库融资机构账户状态审核中
			BankAccInfoDTO accDto=new BankAccInfoDTO ();
			accDto.setAudStsCd(Integer.parseInt(FriBaseInfoConstant.BANK_ACC_AUD_STS_IN));//设置状态
			accDto.setId(Long.parseLong(id));//id
			accDto.setNextAssigneeId(CurrentThreadContext.getCurrentUserId().toString());
			bankAccInfoApiService.modify(accDto);//更新数据库融资机构账户状态
			/*
			 * if(null != dataResultDTO.getInfo() && StringUtils.isNotEmpty(dataResultDTO.getInfo())){ StringBuffer info = new StringBuffer();
			 * info.append(result.getInfo()); info.append(SysLogConstant.LOG_FLOW_NEXT_TASK_OPERATOR); info.append(dataResultDTO.getInfo());//操作人
			 * result.setInfo(info.toString()); }
			 */
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "addFlowStartForAccount",
					"错误[BaseException],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" + e.getMessage(),
					CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addFlowStartForAccount",
					"错误[Exception],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" + e.getMessage(),
					CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		}
		return result;
	}
	/**
	 * 到我的任务管理列表页面
	 */
	@RequestMapping(value = "/toFriBaseFlow.do", method = { RequestMethod.GET })
	public ModelAndView toFriBaseFlowPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friBaseFlow");
		view.addObject("id", request.getParameter("id"));
		return view;
	}

	/**
	 * 初始化待办管理列表 本查询条件不加入当前人作为查询条件,就是说可以查询出来所有的任务,包括未设置处理人的任务
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initFriBaseFlowList.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object initFriBaseFlowList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");

		String id = request.getParameter("id");

		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		FriBaseInfoQueryCondition condition = new FriBaseInfoQueryCondition();

		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		condition.setId(Long.valueOf(id));

		page.setCondition(condition);

		Pager pager = this.friBaseInfoService.searchFlowPageById(page);
		List<FriBaseFlowDTO> list = (List<FriBaseFlowDTO>) pager.getResultList();
		List<FriBaseFlowVO> voList = FriBaseFlowVOTransform.toVOList(list);

		// // 根据流程编号得到一条流程信息
		// for (FriBaseFlowVO friBaseFlowVO : voList) {
		//
		// FlowQueryCondition flowQueryCondition = new FlowQueryCondition();
		// flowQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		// flowQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		// flowQueryCondition.setProcNo(friBaseFlowVO.getpNo());
		// page.setCondition(flowQueryCondition);
		//
		// Pager flowMyTaskPager = this.flowService.searchTaskRecordManagePage(page, CurrentThreadContext.getCurrentUserId(), "");
		// List<FlowMyTaskVO> flowMyTasklist = (List<FlowMyTaskVO>) flowMyTaskPager.getResultList();
		// if (CollectionUtils.isNotEmpty(flowMyTasklist)) {
		// friBaseFlowVO.setFlowMyTaskVo(flowMyTasklist.get(0));
		// }
		// }

		ListPageVO<FriBaseFlowVO> listPage = new ListPageVO<FriBaseFlowVO>(voList, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	/**lxb
     * 到选择列表页面
     */
    @RequestMapping(value = "/toChooseListPage.do", method = {RequestMethod.GET})
    public ModelAndView toChooseListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toChooseListPage", "加载银行账户选择列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("rfbase/fribaseinfo/friBankAccInfoChoose");
        mav.addObject("fundRasInsId", request.getParameter("fundRasInsId"));
        return mav;
    }
	/**
	 * 初始化帐号列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initBaList.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object initBaList(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String accTypCd = request.getParameter("accTypCd");
		String accNum = request.getParameter("accNum");
		BaseLogUtils.info(logger, "initBaList", "查询数据开始.DATA:" , CurrentThreadContext.getCurrentUserName());
		
		BankAccInfoQueryCondition condition=new BankAccInfoQueryCondition();
		if (StringUtils.isNotBlank(accTypCd)) {
			condition.setAccTypCd(accTypCd);
		}
		if (StringUtils.isNotBlank(accNum)) {
			condition.setAccNum(accNum);
		}
		List<BankAccInfoVO> voList = (List<BankAccInfoVO>)  this.friBaseInfoService.selectListForPay(condition);
		ListPageVO<BankAccInfoVO> listPage = new ListPageVO<BankAccInfoVO>(voList, voList.size());

		BaseLogUtils.info(logger, "initBaList", "查询数据完成. DATA:" + JSONObject.toJSONString(listPage), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	/**lxb
	 * 得到一条记录
	 */
	@RequestMapping(value = "/getAccById.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object getAccById(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功!");
		BankAccInfoVO vo = null;
		try {
			vo = this.friBaseInfoService.selectAccById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			result.setData(vo);
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误!");
			BaseLogUtils.error(logger, "getById", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**lxb
     * 放款账号优先级维护
     */
    @RequestMapping(value = "/payAccManage.do", method = {RequestMethod.GET})
    public ModelAndView payAccManage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "payAccManage", "放款账号优先级维护页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("rfbase/fribaseinfo/friPayAccManage");

        List<KeyValueVO> list = friBaseInfoService.getKvList(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD);
		List<KeyValueVO> listn=new ArrayList<KeyValueVO>();
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getKey().equals(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_ZY)
				||	list.get(i).getKey().equals(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_ZG)
				||list.get(i).getKey().equals(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_PRE)
					) {
				listn.add(list.get(i));
			}
		}
		mav.addObject("accTypCdList",listn);
        return mav;
    }
    /**lxb
	 * 到新增修改页面自有帐号
	 */
	@RequestMapping(value = "/toAddPayAccPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPayAccPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friPayAccAdd");
		String id = request.getParameter("id");
		BaseLogUtils.info(logger, "toAddPayAccPage"+id,CurrentThreadContext.getCurrentUserName());
		view.addObject("id", id);
		view.addObject("accTypCd",FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_ZY);
		view.addObject("accTypCdPre",FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_PRE);//add pre-abs账户  by gengchunlan 20180227
		view.addObject("flag",request.getParameter("flag"));
		//add 可投放事业部  by gengchunlan 20180227
		List<KeyValueVO> buOrgCdsNmList =friBaseInfoService.getKvList("SYS0031");
		view.addObject("buOrgCdsNmJSON", JSONObject.toJSONString(buOrgCdsNmList));
		//add 金融机构名称 by gengchunlan 20180302
		if (StringUtils.isNotBlank(id)) {
			BankAccInfoVO bankAccInfo = this.friBaseInfoService.selectAccById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			view.addObject("bankAccInfo", bankAccInfo);
		}
		//end by gengchunlan 20180302
		List<KeyValueVO> projectTypeList = this.prjBscInfoService.getPrjTypCdALLKV();//项目类型
		List<KeyValueVO> areaList =friBaseInfoService.getKvList(FriBaseInfoConstant.FNC_FORBID_PROVINCE);//不可投放地区省份
		//遍历areaList
		StringBuffer sb =new StringBuffer();
		if(CollectionUtil.isNotEmpty(areaList)) {
			for(KeyValueVO obj: areaList) {
				sb.append(obj.getKey());
				sb.append(";");
			}	
		}
		view.addObject("projectTypeList", JSON.toJSONString(projectTypeList));
		view.addObject("areaList", JSON.toJSONString(areaList));
		view.addObject("areaAllStr",sb.toString());
		view.addObject("accStsCdList",this.friBaseInfoService.getAccStsCd());
		BaseLogUtils.info(logger, "toAddPayAccPage@@"+id,CurrentThreadContext.getCurrentUserName());
		return view;
	}
	/**
	 * 可投放款项
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/getpurpCd.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object getpurpCd(HttpServletRequest request, HttpServletResponse response) {
		//可投放款项
				List<KeyValueVO> accTyp =sysDictionaryApiService.getKvList(FriBaseInfoConstant.BANK_ACC_INFO_PURP_CD,CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentOrgCd());
				for (int j = 0; j < accTyp.size(); j++) {
					accTyp.get(j).setValue(accTyp.get(j).getValue().replace("账号", ""));
				}
				return accTyp;
	}
	/**
	 * 添加账户
	 * @param entity
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/addPayAcc.do", method = { RequestMethod.GET , RequestMethod.POST} )
	@ResponseBody
	public Object addPayAcc(BankAccInfoVO entity,HttpServletRequest request, HttpServletResponse response) {
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		BaseLogUtils.info(logger, "addPayAcc"+entity,CurrentThreadContext.getCurrentUserName());
		try {
			Long mainId = this.friBaseInfoService.addPayAcc(entity);
			//add 批次信息的可投放事业部，顺序字段的修改 by gengchunlan 20180227
			 String batchJsonString=request.getParameter("batchJSON");
			 List<FncPreAbsLimVO> batchList = new ArrayList<>();
			 if(StringUtils.isNotEmpty(batchJsonString)){
				 batchList = JSON.parseArray(batchJsonString, FncPreAbsLimVO.class);
			 }
			 if(CollectionUtils.isEmpty(batchList)){
				 BaseLogUtils.info(logger, "addPayAccbatchList"+batchJsonString,CurrentThreadContext.getCurrentUserName());
			 }else{
				for (FncPreAbsLimVO batchVO : batchList) {
					batchVO.setAccNo(entity.getAccNum());
					this.fncPreAbsLimService.modify(batchVO);
					BaseLogUtils.info(logger, "modify", "更新数据.[insId=" + batchVO.getId() + "] DATA:" + JSONObject.toJSONString(batchVO),
							CurrentThreadContext.getCurrentUserName());
				}
			 }//end by gengchunlan 20180227
			bankAccInfoApiService.modifyBankAccById(BankAccInfoVOTransform.toDTO(entity));//更新ltv by gengchunlan 20200402
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("新增成功!");
			BaseLogUtils.info(logger, "addPayAcc", "新增数据 , ID:" + mainId, CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "addPayAcc", "新增数据失败," + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "addPayAcc", "新增数据失败," + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**
	 * 账户排序
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/changeNum.do", method = { RequestMethod.GET , RequestMethod.POST} )
	@ResponseBody
	public Object changeNum(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String num = request.getParameter("num");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		BaseLogUtils.info(logger, "addPayAcc",CurrentThreadContext.getCurrentUserName());
		try {
			this.friBaseInfoService.changeNum(id,num);
			
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("成功!");
			BaseLogUtils.info(logger, "addPayAcc", "数据 , ID:" + id, CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "addPayAcc", "失败," + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("失败!");
			BaseLogUtils.error(logger, "addPayAcc", "失败," + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**lxb
     * 放款账号余额更新
     */
    @RequestMapping(value = "/syncBankAcc.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object syncBankAcc(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "syncBankAcc",  CurrentThreadContext.getCurrentUserName());
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "成功!");
        this.friBaseInfoService.syncBankAcc();
        result.setSuccess(BaseConstant.IS_YESNO_YES);
		result.setInfo("成功!");
        return result;
    }
	/**
	 * 校验帐号重复
	 * @param request
	 * @param response
	 * @return
	 * 2018年2月24日 
	 * lxb
	 */
    @RequestMapping(value = "/checkAcc.do", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public Object checkAcc(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "syncBankAcc",  CurrentThreadContext.getCurrentUserName());
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "成功!");
        String id = request.getParameter("id");
		String accNum = request.getParameter("accNum");
		if (accNum!=null) {
			BankAccInfoQueryCondition condition=new BankAccInfoQueryCondition();
			condition.setAccNum(accNum);
			List<BankAccInfoVO> voList = (List<BankAccInfoVO>)  this.friBaseInfoService.selectListForPay(condition);
			if (!StringUtils.isBlank(id)&&voList!=null&&voList.size()>0) {
				for (int i = 0; i < voList.size(); i++) {
					//修改帐号，运行一样
					if (voList.get(i).getId().toString().equals(id)) {
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo("不存在!");
						break;
					}
				}
			}else if (StringUtils.isBlank(id)&&voList!=null&&voList.size()>0){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("成功!");
			}else {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("不存在!");
			}
			
		}else {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("不存在!");
		}
        
        return result;
    }
    /**
	 * 再融资机构账户审核流程详情页面
	 */
	@RequestMapping(value = "/toBankAccDetailPage.do", method = { RequestMethod.GET })
	public ModelAndView toBankAccDetailPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friBankAccInfoDetail");
		String id = request.getParameter("id");//融资机构账户id
		BankAccInfoVO bankAccInfoVO=BankAccInfoVOTransform.toVO(bankAccInfoApiService.selectById(Long.parseLong(id),CurrentThreadContext.getCurrentSysCd(),
				CurrentThreadContext.getCurrentOrgCd()));
		if(bankAccInfoVO.getFundRasInsId()!=null && !"".equals(bankAccInfoVO.getFundRasInsId())){
			FriBaseInfoVO friBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(bankAccInfoVO.getFundRasInsId()), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			view.addObject("friBaseInfo", friBaseInfoVO);
		}
		view.addObject("bankAccInfo", bankAccInfoVO);
		view.addObject("id", id);
		// 融资机构类型
		List<KeyValueVO> insTypeList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_TYPE_CD);
		view.addObject("insTypeList", insTypeList);
		// 银行 账户类型
		List<KeyValueVO> pubVerPriCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.BANK_ACC_INFO_PUB_VER_PRI_CD);
		view.addObject("pubVerPriCdList", pubVerPriCdList);
		// 是否为ABS
		List<KeyValueVO> yesNoList = friBaseInfoService.searchYesNoKVList();
		view.addObject("yesNoList", yesNoList);
		return view;
	}
	/**
	 * 再融资机构账户审核流程修改页面
	 */
	@RequestMapping(value = "/toBankAccModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toBankAccModifyPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friBankAccInfoModify");
		String id = request.getParameter("id");//融资机构账户id
		String aflag = request.getParameter("aflag");//aflag
		view.addObject("id", id);
		view.addObject("aflag", aflag);
		//机构账户信息
		BankAccInfoVO bankAccInfoVO=BankAccInfoVOTransform.toVO(bankAccInfoApiService.selectById(Long.parseLong(id),CurrentThreadContext.getCurrentSysCd(),
				CurrentThreadContext.getCurrentOrgCd()));
		if(bankAccInfoVO.getFundRasInsId()!=null && !"".equals(bankAccInfoVO.getFundRasInsId())){
			//融资机构信息
			FriBaseInfoVO friBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(bankAccInfoVO.getFundRasInsId()), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			view.addObject("friBaseInfo", friBaseInfoVO);
		}
		//下一节点处理人信息
		if(null!=bankAccInfoVO.getNextAssigneeId() && !"".equals(bankAccInfoVO.getNextAssigneeId())){
			SysUsrDTO userVO=sysUsrApiService.selectSysUsrById(Long.parseLong(bankAccInfoVO.getNextAssigneeId()),CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			view.addObject("userVO", userVO);
		}
		view.addObject("bankAccInfo", bankAccInfoVO);
		// 融资机构类型
		List<KeyValueVO> insTypeList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_TYPE_CD);
		view.addObject("insTypeList", insTypeList);
		// 银行 账户类型
		List<KeyValueVO> pubVerPriCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.BANK_ACC_INFO_PUB_VER_PRI_CD);
		view.addObject("pubVerPriCdList", pubVerPriCdList);
		// 是否为ABS
		List<KeyValueVO> yesNoList = friBaseInfoService.searchYesNoKVList();
		view.addObject("yesNoList", yesNoList);
		return view;
	}
	/**
	 * 再融资机构账户修改保存
	 */
	@RequestMapping(value = "/modifyBankAccInfo.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object modifyBankAccInfo(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "成功!");
		//获取数据
		String id = request.getParameter("dataId");//融资机构账户id
		String pubVerPriCd = request.getParameter("pubVerPriCd");//融资机构账户账户类型
		String accTypCd = request.getParameter("accTypCd");//融资机构账户账户用途
		String banAccNum = request.getParameter("banAccNum");
		String banAccNm = request.getParameter("banAccNm");
		String accNm = request.getParameter("accNm");
		String accNum = request.getParameter("accNum");
		String rem = request.getParameter("rem");
		String nextAssigneeId = request.getParameter("nextAssigneeId");//下一节点处理人
		if(StringUtils.isNotBlank(id)){
		}else{
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("业务主键不允许为空失败!");
			return result;
		}
		BaseLogUtils.info(logger, "modifyBankAccInfo",CurrentThreadContext.getCurrentUserName(),"id:"+id);
		//封装数据
		BankAccInfoVO bankAccInfoVO =new BankAccInfoVO();
		bankAccInfoVO.setId(Long.parseLong(id));
		bankAccInfoVO.setPubVerPriCd(pubVerPriCd);
		bankAccInfoVO.setAccTypCd(accTypCd);
		bankAccInfoVO.setBanAccNm(banAccNm);
		bankAccInfoVO.setBanAccNum(banAccNum);
		bankAccInfoVO.setAccNm(accNm);
		bankAccInfoVO.setAccNum(accNum);
		bankAccInfoVO.setRem(rem);
		bankAccInfoVO.setNextAssigneeId(nextAssigneeId);
		//保存 
		try{
			bankAccInfoApiService.modify(BankAccInfoVOTransform.toDTO(bankAccInfoVO));
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("成功!");
			BaseLogUtils.info(logger, "modifyBankAccInfo", "数据 , ID:" + id, CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modifyBankAccInfo", "失败," + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("失败!");
			BaseLogUtils.error(logger, "modifyBankAccInfo", "失败," + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	

    /**
     * 跳转到初始化机构帐号列表
     * @param request
     * @param response
     * @return
     */
	@RequestMapping(value = "/toSearchBaListPage.do")
	public ModelAndView toSearchBaListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/searchBaListPage");
		
		view.addObject("fundRasInsId",request.getParameter("fundRasInsId"));
		return view;
	}
    /**
	 * 初始化机构帐号列表[分页]
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/searchBaListPage.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object searchBaListPage(HttpServletRequest request, HttpServletResponse response) throws Exception{

		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String fundRasInsId = request.getParameter("fundRasInsId");//机构id
		if (StringUtils.isBlank(fundRasInsId)) {
			return null;
		}
		
		BankAccInfoQueryCondition qc=new BankAccInfoQueryCondition();
		qc.setFundRasInsId(Long.valueOf(fundRasInsId));
		qc.setBanAccNm(request.getParameter("bkNm"));
		qc.setAccNum(request.getParameter("accNo"));
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		page.setCondition(qc);
		
		
		Pager pager = this.friBaseInfoService.searchBaListPage(page);
		ListPageVO<BankAccInfoVO> listPage = new ListPageVO<BankAccInfoVO>((List<BankAccInfoVO>) pager.getResultList(), pager.getTotalCount());
		BaseLogUtils.info(logger, "", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 机构账户详情页面
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/insAccNoDetail.do")
    public ModelAndView insAccNoDetail(HttpServletRequest request) {
		
		ModelAndView modelAndView = new ModelAndView("rfbase/fribaseinfo/insAccNoDetail");
		
		String id = request.getParameter("id");//机构账户id
		if(StringUtils.isNotBlank(id)) {
			BankAccInfoVO bankAccInfoVO = this.friBaseInfoService.selectAccById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			modelAndView.addObject("bankAccInfoVO",bankAccInfoVO);
		}

		return modelAndView;
    }

	@RequestMapping(value = "/getBankAccInfoList.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object getBankAccInfoList(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO vo = new DataResultVO();
		BaseLogUtils.newLogger("查询机构支持的付款账户信息，request:{}", JSON.toJSONString(request.getParameterMap())).info();
		String insCode = request.getParameter("insCode");
		BankAccInfoQueryCondition condition = new BankAccInfoQueryCondition();
		condition.setInsCode(insCode);
		List<BankAccInfoDTO> bankAccInfoDTOS = bankAccInfoApiService.searchList(condition);
		BaseLogUtils.newLogger("查询机构支持的付款账户信息，insCode:{},bankAccInfoDTOS:{}",insCode, JSON.toJSONString(bankAccInfoDTOS)).info();
		if (CollectionUtils.isNotEmpty(bankAccInfoDTOS)){
			vo.setData(bankAccInfoDTOS);
		}
		vo.setSuccess(1);
		return vo;
	}


	/**
	 * 到机构优先级列表页面
	 */
	@RequestMapping(value = "/toInsNumList.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toInsNumList(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/friBaseInfoNumList");
		FriBaseInfoQueryCondition qc = new FriBaseInfoQueryCondition();
		//qc.setInsUseCd(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_USE_CD_ZG);
		List<String> insUseCds=new ArrayList<String>();
		insUseCds.add(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_USE_CD_ZG);
		insUseCds.add("3");
		qc.setInsUseCds(insUseCds);
		qc.setOrderBy("IS_SERVICE DESC,ZG_NUM ASC");
		
		List<FriBaseInfoVO> list=this.friBaseInfoService.searchList(qc);
		
		//项目类型名称
		Map<String, String> prjTypCdMap = sysDictionaryApiService.searchGroupToMapAll(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_TYPE_CD); 
		
		
		if(CollectionUtils.isNotEmpty(list)) {
			List<Long> insIdList = new ArrayList<Long>();
			for (FriBaseInfoVO friBaseInfoVO : list) {
				insIdList.add(friBaseInfoVO.getId());
			}
			
			List<FundRasInsLimVO> fundRasInsLimList = new ArrayList<FundRasInsLimVO>();
			List<CrBaseInfoVO> crBaseInfoVOList = new ArrayList<CrBaseInfoVO>();
			
			if(insIdList.size() >0) {
				FundRasInsLimQueryCondition fundRasInsLimQueryCondition = new FundRasInsLimQueryCondition();
				fundRasInsLimQueryCondition.setInsIdList(insIdList);
				fundRasInsLimList = fundRasInsLimService.searchList(fundRasInsLimQueryCondition);
				
				CrBaseInfoQueryCondition condition = new CrBaseInfoQueryCondition();
				condition.setCrStQ(CrBaseInfoConstant.CR_BSC_INFO_CR_ST_PASS);
				condition.setZgFlag(1);
				condition.setFncInsIdQList(insIdList);
				List<CrBaseInfoDTO> listDTO = crBaseInfoApiService.searchList(condition);
				crBaseInfoVOList = CrBaseInfoVOTransform.toVOList(listDTO);
			}
			BaseLogUtils.info(logger, null, "fundRasInsLimList:" + JSONObject.toJSONString(fundRasInsLimList), CurrentThreadContext.getCurrentUserName());
			BaseLogUtils.info(logger, null, "crBaseInfoVOList:" + JSONObject.toJSONString(crBaseInfoVOList), CurrentThreadContext.getCurrentUserName());
			
			
			
			
			// 授信额度 实际使用额度 余额
			for (FriBaseInfoVO friBaseInfoVO : list) {
						
						BigDecimal crBal = new BigDecimal(0);
						BigDecimal crLmt = new BigDecimal(0);
						
						
						List<CrBaseInfoVO> crBaseInfoVOList2 = this.getCrBaseInfoVOList(friBaseInfoVO.getId(),crBaseInfoVOList);
						
						for (CrBaseInfoVO crBaseInfoVO : crBaseInfoVOList2) {
							crBal = crBal.add(crBaseInfoVO.getCrBal());
							crLmt = crLmt.add(crBaseInfoVO.getCrLmt());
						}
						friBaseInfoVO.setCrBal(crBal);//余额
						friBaseInfoVO.setCrLmt(crLmt);//总额
						friBaseInfoVO.setUseLmt(crLmt.subtract(crBal));//已用
						
						//获取机构限额信息
						if(friBaseInfoVO.getId() != null) {
							
							List<FundRasInsLimVO> fundRasInsLimList2 = this.getFundRasInsLimList(friBaseInfoVO.getId(),fundRasInsLimList);
							//数据转换
							if(CollectionUtils.isNotEmpty(fundRasInsLimList2)) {
								List<Map<String, Object>> fundRasInsLimMapList = new ArrayList<Map<String, Object>>(fundRasInsLimList.size());
									
								for (FundRasInsLimVO fundRasInsLim : fundRasInsLimList2) {
									Map<String, Object> fundRasInsLimMap = new HashMap<String, Object>();
									//设置项目类型
									if(prjTypCdMap != null && prjTypCdMap.size() >0) {
										if (prjTypCdMap.containsKey(fundRasInsLim.getPrjTypCd())) {
											fundRasInsLimMap.put("PRJ_TYP", prjTypCdMap.get(fundRasInsLim.getPrjTypCd()));
					                    }
									}
									
									String insLimAmtStr = "无";
									Double insLimAmt = fundRasInsLim.getInsLimAmt();
									if(insLimAmt != null && insLimAmt !=0) {
										NumberFormat nf = NumberFormat.getNumberInstance(Locale.CHINA);
										nf.setGroupingUsed(false);
										insLimAmtStr = nf.format(insLimAmt);
									}
									
									fundRasInsLimMap.put("INS_LIM_AMT_",insLimAmtStr);
									
									Long insLimMum = fundRasInsLim.getInsLimNum();
									fundRasInsLimMap.put("INS_LIM_NUM_",(insLimMum == null || insLimMum ==0)?"无":insLimMum.toString());
									
									Long mainLimNum = fundRasInsLim.getMainLimNum();
									fundRasInsLimMap.put("INS_MAIN_LIM_NUM_",(mainLimNum == null || mainLimNum ==0)?"无":mainLimNum.toString());
									
									
									Long handLimNum = fundRasInsLim.getHandLimNum();
									fundRasInsLimMap.put("INS_HAND_LIM_NUM_",(handLimNum == null || handLimNum ==0)?"无":handLimNum.toString());
									
									String isHang = fundRasInsLim.getIsHang();
									if("1".equals(isHang)) {
										fundRasInsLimMap.put("INS_IS_HANG","支持");
									}else if("0".equals(isHang)) {
										fundRasInsLimMap.put("INS_IS_HANG","不支持");
									}
									
									
									fundRasInsLimMapList.add(fundRasInsLimMap);
								}
							
								//设置页面显示数据
								if(CollectionUtils.isNotEmpty(fundRasInsLimMapList)) {
									friBaseInfoVO.setFundRasInsLimList(fundRasInsLimMapList);
									
									Map<String, Object> fundRasInsMap = fundRasInsLimMapList.get(0);
								
								friBaseInfoVO.setPrjTyp((String)fundRasInsMap.get("PRJ_TYP"));
								friBaseInfoVO.setInsLimAmt((String)fundRasInsMap.get("INS_LIM_AMT_"));
								friBaseInfoVO.setInsLimMum((String)fundRasInsMap.get("INS_LIM_NUM_"));
								friBaseInfoVO.setMainLimNum((String)fundRasInsMap.get("INS_MAIN_LIM_NUM_"));
								friBaseInfoVO.setHandLimNum((String)fundRasInsMap.get("INS_HAND_LIM_NUM_"));
								friBaseInfoVO.setIsHang((String)fundRasInsMap.get("INS_IS_HANG"));
							}
						}
							
						}
			}
			
			view.addObject("insList", list);
			view.addObject("insSize", list.size());
		}
		
		return view;
	}
	
	private List<CrBaseInfoVO> getCrBaseInfoVOList(Long id, List<CrBaseInfoVO> crBaseInfoVOList) {
		
		List<CrBaseInfoVO> returnCrBaseInfoVOList = new ArrayList<CrBaseInfoVO>();
		
		if(id == null || CollectionUtils.isEmpty(crBaseInfoVOList))
			return returnCrBaseInfoVOList;
		
		for (CrBaseInfoVO crBaseInfoVO : crBaseInfoVOList) {
			if(crBaseInfoVO.getFncInsId() != null 
					&& id.equals(crBaseInfoVO.getFncInsId())) {
				returnCrBaseInfoVOList.add(crBaseInfoVO);
			}
		}
		
		return returnCrBaseInfoVOList;
	}

	private List<FundRasInsLimVO> getFundRasInsLimList(Long id, List<FundRasInsLimVO> fundRasInsLimList) {
		
		List<FundRasInsLimVO> returnFundRasInsLimList = new ArrayList<FundRasInsLimVO>();
		
		if(id == null || CollectionUtils.isEmpty(fundRasInsLimList))
			return returnFundRasInsLimList;
		
		for (FundRasInsLimVO fundRasInsLimVO : fundRasInsLimList) {
			if(StringUtils.isNotBlank(fundRasInsLimVO.getInsId())) {
				if(id.equals(Long.parseLong(fundRasInsLimVO.getInsId()))) {
					returnFundRasInsLimList.add(fundRasInsLimVO);
				}
			}
		}
		
		return returnFundRasInsLimList;
	}

	/**
	 * 修改优先级
	 */
	@RequestMapping(value = "/modifyNums.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object modifyNums(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String idstr = request.getParameter("ids");
		String isServicestr = request.getParameter("isServices");
		String zgNumstr = request.getParameter("zgNums");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");

		try {
			String[] ids=idstr.split(",");
			String[] isServices=isServicestr.split(",");
			String[] zgNums=zgNumstr.split(",");
			for (int i = 0; i < ids.length; i++) {
				FriBaseInfoVO entity = new FriBaseInfoVO();
				entity.setId(Long.valueOf(ids[i]));
				entity.setIsService(Integer.valueOf(isServices[i]));
				entity.setZgNum(Integer.valueOf(zgNums[i]));
				entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId()); // 修改人
				entity.setMdfTm(new Date()); // 修改时间
				this.friBaseInfoService.modify(entity);
			}
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("修改成功!");
			BaseLogUtils.info(logger, "modifyNums", "修改数据 ,ids[" + idstr + "].", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modifyNums", "修改数据失败,ids[" + idstr + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("修改失败!");
			BaseLogUtils.error(logger, "modifyNums", "修改数据失败,ids[" + idstr + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 资管机构相似度页面
	 */
	@RequestMapping(value = "similarityDegree.do")
	public ModelAndView similarityDegree(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/similarityDegree");
		FriBaseInfoQueryCondition qc = new FriBaseInfoQueryCondition();
		qc.setInsUseCd(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_USE_CD_ZG);
		List<FriBaseInfoVO> list=this.friBaseInfoService.searchList(qc);
		
		//项目类型名称
		Map<String, String> prjTypCdMap = sysDictionaryApiService.searchGroupToMapAll(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_TYPE_CD); 
		
				
		// 授信额度 实际使用额度 余额
		for (FriBaseInfoVO friBaseInfoVO : list) {
			//获取机构限额信息
			if(friBaseInfoVO.getId() != null) {
				
				FundRasInsLimQueryCondition fundRasInsLimQueryCondition = new FundRasInsLimQueryCondition();
				fundRasInsLimQueryCondition.setInsId(friBaseInfoVO.getId().toString());
				List<FundRasInsLimVO> fundRasInsLimList = fundRasInsLimService.searchList(fundRasInsLimQueryCondition);
				BaseLogUtils.info(logger, null, "fundRasInsLimList:" + JSONObject.toJSONString(fundRasInsLimList), CurrentThreadContext.getCurrentUserName());
				
				//数据转换
				if(CollectionUtils.isNotEmpty(fundRasInsLimList)) {
					List<Map<String, Object>> fundRasInsLimMapList = new ArrayList<Map<String, Object>>(fundRasInsLimList.size());
					
					for (FundRasInsLimVO fundRasInsLim : fundRasInsLimList) {
						Map<String, Object> fundRasInsLimMap = new HashMap<String, Object>();
						//设置项目类型
						if(prjTypCdMap != null && prjTypCdMap.size() >0) {
							if (prjTypCdMap.containsKey(fundRasInsLim.getPrjTypCd())) {
								fundRasInsLimMap.put("PRJ_TYP", prjTypCdMap.get(fundRasInsLim.getPrjTypCd()));
		                    }
						}
						
						//融资额上限（万），不使用科学计数法
						Double insLimAmt = fundRasInsLim.getInsLimAmt();
						String insLimAmtStr = "无";
						if(insLimAmt != null && insLimAmt !=0) {
							NumberFormat nf = NumberFormat.getNumberInstance(Locale.CHINA);
							nf.setGroupingUsed(false);
							insLimAmtStr = nf.format(insLimAmt);
						}
						fundRasInsLimMap.put("INS_LIM_AMT_",insLimAmtStr);
						
						Long insLimMum = fundRasInsLim.getInsLimNum();
						fundRasInsLimMap.put("INS_LIM_NUM_",(insLimMum == null || insLimMum ==0)?"无":insLimMum.toString());
						
						fundRasInsLimMapList.add(fundRasInsLimMap);
					}
					
					//设置页面显示数据
					if(CollectionUtils.isNotEmpty(fundRasInsLimMapList)) {
						friBaseInfoVO.setFundRasInsLimList(fundRasInsLimMapList);
						
						Map<String, Object> fundRasInsMap = fundRasInsLimMapList.get(0);

						friBaseInfoVO.setPrjTyp((String)fundRasInsMap.get("PRJ_TYP"));
						friBaseInfoVO.setInsLimAmt((String)fundRasInsMap.get("INS_LIM_AMT_"));
						friBaseInfoVO.setInsLimMum((String)fundRasInsMap.get("INS_LIM_NUM_"));
					}
				}
				
			}
		}
		view.addObject("insList", list);
		view.addObject("insSize", list.size());
		return view;
	}

	
	
	@RequestMapping(value = "/getInsRepayType.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object getInsRepayType(HttpServletRequest request, HttpServletResponse response) {
		// 还款方式
		List<KeyValueVO> list = friBaseInfoService.getKvList(FriBaseInfoConstant.INS_REPAY_TYPE_CD);
		
		return list;
		
	}
	@Autowired
    private ICapPayeeInfoApiService capPayeeInfoApiService;
   
	@RequestMapping(value = "/getPayRule.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object getPayRule(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		
		Long t= capPayeeInfoApiService.payRule(Long.parseLong(id));
		result.setInfo(t.toString());
		return result;
	}
	
	/**
	 * 点击上下箭头，调整资管机构优先级
	 */
	@RequestMapping(value = "/modifyPriority.do")
	@ResponseBody
	public Object modifyPriority(HttpServletRequest request) {
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_NO);

		try {

			String id = request.getParameter("id");//资管机构id
			String relId = request.getParameter("relId");//上一个或下一个资管机构
			
			if(StringUtils.isBlank(id)) {
				result.setInfo("id不可为空");
				return result;
			}
			
			if(StringUtils.isBlank(relId)) {
				result.setInfo("relId不可为空");
				return result;
			}
			
			FriBaseInfoVO friBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			if(friBaseInfoVO == null) {
				result.setInfo("friBaseInfoVO不存在，id:"+id);
				return result;
			}
			
			FriBaseInfoVO relFriBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(relId), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			if(relFriBaseInfoVO == null) {
				result.setInfo("relFriBaseInfoVO不存在，relId:"+relId);
				return result;
			}
			
			BaseLogUtils.info(logger, "modifyPriority", "modifyPriority交换前:friBaseInfoVO:" + JSON.toJSONString(friBaseInfoVO) + " relFriBaseInfoVO=" +JSON.toJSONString(relFriBaseInfoVO), CurrentThreadContext.getCurrentUserName());
			
			friBaseInfoService.modifyExchangePriority(friBaseInfoVO, relFriBaseInfoVO);
			
			BaseLogUtils.info(logger, "modifyPriority", "modifyPriority交换后:friBaseInfoVO:" + JSON.toJSONString(friBaseInfoVO) + " relFriBaseInfoVO=" +JSON.toJSONString(relFriBaseInfoVO), CurrentThreadContext.getCurrentUserName());
			result.setSuccess(BaseConstant.IS_YESNO_YES);
		}catch (Exception ex) {
			result.setInfo("操作失败,"+ex.getMessage());
			BaseLogUtils.error(logger, "modifyPriority", "modifyPriority调用异常,"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
			
		}
		return result;
	}
	
	/**
	 * 修改资管机构是否服务
	 */
	@RequestMapping(value = "/modifyIsService.do")
	@ResponseBody
	public Object modifyIsService(HttpServletRequest request) {
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_NO);

		try {
			String id = request.getParameter("id");//资管机构id
			String isService = request.getParameter("isService");//是否服务
			
			if(StringUtils.isBlank(id)) {
				result.setInfo("id不可为空");
				return result;
			}
			
			if(StringUtils.isBlank(isService)) {
				result.setInfo("isService不可为空");
				return result;
			}
			
			FriBaseInfoVO friBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			if(friBaseInfoVO == null) {
				result.setInfo("friBaseInfoVO不存在，id:"+id);
				return result;
			}
			
			//1、保存是否服务
			FriBaseInfoVO friBaseInfoVOUpdate = new FriBaseInfoVO();
			
			friBaseInfoVOUpdate.setId(friBaseInfoVO.getId());
			friBaseInfoVOUpdate.setIsService(Integer.parseInt(isService));
			friBaseInfoVOUpdate.setMdfTm(new Date());
			friBaseInfoVOUpdate.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			
			BaseLogUtils.info(logger, "modifyIsService", "modifyIsService修改前:friBaseInfoVOUpdate:" + JSON.toJSONString(friBaseInfoVOUpdate) , CurrentThreadContext.getCurrentUserName());
			
			friBaseInfoService.modify(friBaseInfoVOUpdate);
			
			BaseLogUtils.info(logger, "modifyIsService", "modifyIsService修改后:friBaseInfoVOUpdate:" + JSON.toJSONString(friBaseInfoVOUpdate) , CurrentThreadContext.getCurrentUserName());
			
			
			//2、获取排序后所有列表数据
//			FriBaseInfoQueryCondition qc = new FriBaseInfoQueryCondition();
//			qc.setInsUseCd(FriBaseInfoConstant.FUND_RAS_INS_BASE_INFO_INS_USE_CD_ZG);
//			qc.setOrderBy("IS_SERVICE DESC,ZG_NUM ASC");
//			
//			List<FriBaseInfoVO> friBaseInfoVOList = this.friBaseInfoService.searchList(qc);
//			BaseLogUtils.newLogger("查下结果friBaseInfoVOList:"+JSON.toJSONString(friBaseInfoVOList)).info();
//			if (CollectionUtils.isEmpty(friBaseInfoVOList)) {
//				result.setInfo("friBaseInfoVOList不存在，qc="+JSON.toJSONString(qc));
//				return result;
//			}
//			
//			//3 找出当前对象所在list位置，开始排序(交换优先级)
//			//3.1去掉不符合条件的服务对象
//		    Iterator<FriBaseInfoVO> it = friBaseInfoVOList.iterator();
//		    while(it.hasNext()){
//		    	FriBaseInfoVO currentFriBaseInfoVO = it.next();
//				if("1".equals(isService) ) {//是否服务:是
//					if(currentFriBaseInfoVO.getIsService()==0) {
//						it.remove();
//					}
//				} else {//是否服务:否
//					if(currentFriBaseInfoVO.getIsService()==1) {
//						it.remove();
//					}
//				}
//				
//			}
//		    BaseLogUtils.newLogger("去掉不符合条件的服务对象后friBaseInfoVOList:"+JSON.toJSONString(friBaseInfoVOList)).info();
//			//3.2去除上排对象和自身对象
//		    Iterator<FriBaseInfoVO> it2 = friBaseInfoVOList.iterator();
//		    while(it2.hasNext()){
//		    	FriBaseInfoVO currentFriBaseInfoVO = it2.next();
//				if(!friBaseInfoVO.getId().equals(currentFriBaseInfoVO.getId())) {
//					it2.remove();
//				}else if(friBaseInfoVO.getId().equals(currentFriBaseInfoVO.getId())) {
//					it2.remove();
//					break;
//				}
//			}
//		    BaseLogUtils.newLogger("去除上排对象和自身对象后friBaseInfoVOList:"+JSON.toJSONString(friBaseInfoVOList)).info();
//		    
//			//3.3 开始交换当前对象和其他对象，将当前对象移动到最下方
//			for (FriBaseInfoVO currentFriBaseInfoVO : friBaseInfoVOList) {
//				friBaseInfoService.modifyExchangePriority(friBaseInfoVO, currentFriBaseInfoVO);
//			}
			
			
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			BaseLogUtils.info(logger, "modifyIsService", "modifyIsService修改成功" , CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			ex.printStackTrace();
			result.setInfo("操作失败,"+ex.getMessage());
			BaseLogUtils.error(logger, "modifyIsService", "modifyIsService调用异常,"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**
	 *	 根据再融资机构id修改账户修改保存
	 *	@author gengchunlan
	 *	@date 20200401
	 */
	@RequestMapping(value = "/modifyBankAccByInsId.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object modifyBankAccByInsId(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String bankArray = request.getParameter("bankArray"); // 银行帐号信息
		BaseLogUtils.info(logger, "modifyBankAccByInsId", "修改数据,bankArray[" + JSON.toJSONString(bankArray) + "].", CurrentThreadContext.getCurrentUserName());
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		try {
			
			FriBaseInfoVO entity = new FriBaseInfoVO();
			entity.setId(Long.valueOf(id));
			// 银行帐号信息
			JSONArray bankJsonArray = JSONArray.parseArray(bankArray);
			List<BankAccInfoVO> bankAccInfoVOs = new ArrayList<>();
			if (bankJsonArray.size() > 0) {
				for (int i = 0; i < bankJsonArray.size(); i++) {
					BankAccInfoVO bankAccInfoVO = JSONObject.toJavaObject(bankJsonArray.getJSONObject(i), BankAccInfoVO.class);
					bankAccInfoVOs.add(bankAccInfoVO);
				}
			}
			if (friBaseInfoService.isAccNumExist(bankAccInfoVOs)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_606, "银行帐号不能重复!");
			}
			entity.setBankAccInfoVOs(bankAccInfoVOs);
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId()); // 修改人
			entity.setMdfTm(new Date()); // 修改时间
			this.friBaseInfoService.modify(entity);
			
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("更新成功!");
			BaseLogUtils.info(logger, "modifyBankAccByInsId", "修改数据,id[" + id + "].", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modifyBankAccByInsId", "失败," + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("失败!");
			BaseLogUtils.error(logger, "modifyBankAccByInsId", "失败," + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**
	 * 跳转到维护机构详情页面 【融担数据上报功能 金融机构 维护机构详情功能】
	 */
	@RequestMapping(value = "/modifyDetailPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView modifyDetailPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/fundModifyDetailPage");
		String id = request.getParameter("id");
		view.addObject("id", id);
		BaseLogUtils.info(logger, "modifyDetailPage", "跳转页面,friVo[" + id + "].",
				CurrentThreadContext.getCurrentUserName());
		BaseLogUtils.newServiceLogger("===修改数据,friVo:" + JSON.toJSONString(id)).info();
		// 金融机构类型
		List<KeyValueVO> fundInsTypeList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_INS_TYPE);
		view.addObject("fundInsTypeList", fundInsTypeList);
		// 金融机构属性
		List<KeyValueVO> fundInsPropList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_INS_PROP);
		view.addObject("fundInsPropList", fundInsPropList);
		// 证件类型
		List<KeyValueVO> certTypCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.CODE_GRP_CERT_TYP_CD);
		;
		view.addObject("certTypCdListJSON", JSON.toJSON(certTypCdList));
		// 联系人类型
		List<KeyValueVO> rlTypCDList = friBaseInfoService.getKvList(FriBaseInfoConstant.CODE_RL_TYP_CD);
		view.addObject("rlTypCDListJSON", JSONObject.toJSONString(rlTypCDList));
		// 万元美元
		List<KeyValueVO> capUntCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.CODE_GRP_REG_CAP_UNT_CD);
		view.addObject("capUntCdList", capUntCdList);
		FriBaseInfoVO vo = new FriBaseInfoVO();
		view.addObject("isRlpsn", 0);
		if (StringUtils.isNotBlank(id)) {
			vo = friBaseInfoService.selectById(Long.parseLong(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			//格式化注册时间 合作时间
			if(vo!=null) {
				if(vo.getRegCapTm()!=null) {
					vo.setRegCapTmStr(DateUtils.formatDateToString(vo.getRegCapTm(), DateUtils.YYYY_MM_DDHHMMSS));
				}
				if(vo.getCoopTm()!=null){
					vo.setCoopTmStr(DateUtils.formatDateToString(vo.getCoopTm(), DateUtils.YYYY_MM_DDHHMMSS));
				}
			}
			// 查询主要联系人
			FundRasInsRlPsnQueryCondition psn = new FundRasInsRlPsnQueryCondition();
			psn.setFundId(Long.parseLong(id));
			List<FundRasInsRlPsnVO> fundRasInsRlPsnVOs = FundRasInsRlPsnVOTransform
					.toVOList(fundRasInsRlPsnApiService.searchList(psn));
			vo.setFundRasInsRlPsnVOs(fundRasInsRlPsnVOs);
			view.addObject("friVo", vo);
			if(fundRasInsRlPsnVOs!=null && fundRasInsRlPsnVOs.size()>0) {
				view.addObject("isRlpsn", fundRasInsRlPsnVOs.size());
			}
		} else {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "金融机构id不能为空!");
		}
		BaseLogUtils.newServiceLogger("===修改数据,friVo:" + JSON.toJSONString(vo)).info();
		BaseLogUtils.info(logger, "modifyDetailPage", "修改数据,friVo[" + JSON.toJSONString(vo) + "].",
				CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 保存维护机构详情信息 【融担数据上报功能 金融机构 维护机构详情功能】
	 */
	@RequestMapping(value = "/saveFundDetail.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object saveFundDetail(HttpServletRequest request, HttpServletResponse response) throws Exception {

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		String id = request.getParameter("id");
		String uscc = request.getParameter("uscc");// 统一社会信用代码
		String regCapTm = request.getParameter("regCapTm");// 注册时间
		String regAddr = request.getParameter("regAddr");// 注册地址
		String fullAddr = request.getParameter("fullAddr");// 详细地址维护
		String regCapAmt = request.getParameter("regCapAmt");//// 注册资金
		String regCapUntCd = request.getParameter("regCapUntCd");//// 注册资金计量单位
		String fundInsProp = request.getParameter("fundInsProp");//// 机构属性
		String fundInsType = request.getParameter("fundInsType");// 机构类型
		String coopTm = request.getParameter("coopTm");// 合作时间
		String guaranteeCoopNum = request.getParameter("guaranteeCoopNum");// 融担公司企业编号
		String rgnProvCd = request.getParameter("rgnProvCd");// 区域省
		String rgnCyCd = request.getParameter("rgnCityCd");// 区域市
		String remark = request.getParameter("remark");// 备注
		String friRlPsnGrid = request.getParameter("friRlPsnGrid");// 主要人员信息

		try {
			if (StringUtils.isEmpty(id)) {
				throw new BaseException(BaseExceptionConstant.COMMON_0001, "融资机构id不能为空!");
			}
			FriBaseInfoVO entity = new FriBaseInfoVO();
			entity.setId(Long.valueOf(id));
			if (StringUtils.isNotBlank(regCapTm)) {
				entity.setRegCapTm(DateUtils.formatStringToDate(regCapTm, DateUtils.YYYY_MM_DDHHMMSS));
			}
			if (StringUtils.isNotBlank(regCapAmt)) {
				entity.setRegCapAmt(new BigDecimal(regCapAmt));
			}
			if (StringUtils.isNotBlank(coopTm)) {
				entity.setCoopTm(DateUtils.formatStringToDate(coopTm, DateUtils.YYYY_MM_DDHHMMSS));
			}
			
			entity.setUscc(uscc);
			entity.setRegAddr(regAddr);
			entity.setRegCapUntCd(regCapUntCd);
			entity.setFundInsProp(fundInsProp);
			entity.setFundInsType(fundInsType);
			entity.setFullAddr(fullAddr);
			entity.setGuaranteeCoopNum(guaranteeCoopNum);
			entity.setRgnPrCd(rgnProvCd);
			entity.setRgnCyCd(rgnCyCd);
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId()); // 修改人
			entity.setMdfTm(new Date()); // 修改时间
			entity.setRemark(remark);
			this.friBaseInfoService.modify(entity);
			// 更新保存联系人信息
			net.sf.json.JSONArray arrayRl = net.sf.json.JSONArray.fromObject(friRlPsnGrid);
			List<FundRasInsRlPsnVO> rlList = net.sf.json.JSONArray.toList(arrayRl, FundRasInsRlPsnVO.class);
			BaseLogUtils.newServiceLogger("===saveFundDetailarrayRl[" + JSON.toJSONString(friRlPsnGrid) + "].").info();
			List<FundRasInsRlPsnVO> addList = new ArrayList<>();// 新增list
			List<FundRasInsRlPsnVO> modifyList = new ArrayList<>();// 修改list
			if (CollectionUtils.isNotEmpty(rlList)) {
				for (FundRasInsRlPsnVO rlVo : rlList) {
					if (rlVo != null) {
						if (StringUtils.isNotEmpty(rlVo.getId())) {
							rlVo.setMdfTm(new Date());
							rlVo.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
							fundRasInsRlPsnApiService.modify(FundRasInsRlPsnVOTransform.toDTO(rlVo));
							modifyList.add(rlVo);
						} else {
							rlVo.setCrtTm(new Date());
							rlVo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
							rlVo.setIsDel(BaseConstant.IS_YESNO_NO);
							rlVo.setFundId(Long.valueOf(id));
							fundRasInsRlPsnApiService.add(FundRasInsRlPsnVOTransform.toDTO(rlVo));
							addList.add(rlVo);
						}
					}
				}
			} // end 更新主要人员信息
			BaseLogUtils.newServiceLogger("===saveFundDetail addList[" + JSON.toJSONString(addList) + "]."
					+ "modifyList" + JSON.toJSONString(modifyList)).info();
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("更新成功!");
			BaseLogUtils.newServiceLogger("===saveFundDetail修改数据成功,entity[" + JSON.toJSONString(entity) + "].").info();
		} catch (BaseException ex) {
			ex.printStackTrace();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newServiceLogger("===saveFundDetail修改数据失败,id[" + id + "]." + ex.getMessage()).info();
		} catch (Exception ex) {
			ex.printStackTrace();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误");
			BaseLogUtils.newServiceLogger("===saveFundDetail修改数据失败,id[" + id + "]." + ex.getMessage()).info();
		}
		return result;
	}
	
	
	/**
	 * 金融机构详情-备案资料（附件页面）
	 */
	@RequestMapping(value = "/recordInfo.do")
	public Object recordInfo(HttpServletRequest request) {
		
		return "rfbase/fribaseinfo/recordInfo";
	}
	
	/**
	 * 金融机构详情-备案资料（加载附件列表）
	 */
	@RequestMapping(value = "/recordInfoFileList.do")
	@ResponseBody
	public Object recordInfoFileList(HttpServletRequest request) {
		
        String friId = request.getParameter("friId");//金融机构id
        if(StringUtils.isBlank(friId)) return null;
        
        SysUlDatCfgQueryCondition ulDatCfgQueryCondition = new SysUlDatCfgQueryCondition();
		
		List<String> cfgCdList = new ArrayList<>();
		cfgCdList.add("REF002");
		
		ulDatCfgQueryCondition.setCfgCdList(cfgCdList);
		ulDatCfgQueryCondition.setDataId(friId);
		ulDatCfgQueryCondition.setOrgCd(FncPrjContMainConstant.ORG_CODE);
		ulDatCfgQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		
		BaseLogUtils.newLogger("===ulDatCfgQueryCondition:"+JSON.toJSONString(ulDatCfgQueryCondition)).info();
		List<SysUlDatCfgDTO> sysUlDatCfgDTOList = uploadApiService.searchSysUlDatCfgListByDataId(ulDatCfgQueryCondition);
		BaseLogUtils.newLogger("===sysUlDatCfgDTOList:"+JSON.toJSONString(sysUlDatCfgDTOList)).info();
		
        if (CollectionUtils.isNotEmpty(sysUlDatCfgDTOList)) {
        	Map<String, String> audStsCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapitalConstant.CODE_MATE_AUD_STS_CD);
        	String picServicePath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);//设置文件路径
        	List<CapPayMaterialVo> voList = new ArrayList<CapPayMaterialVo>();
			
			for (SysUlDatCfgDTO sysUlDatCfgDTO : sysUlDatCfgDTOList) {
				for (SysUlDatCfgDtlDTO sysUlDatCfgDtlDTO : sysUlDatCfgDTO.getSysUlDatCfgDtlDTOList()) {
					this.setCapPayMaterialVo(sysUlDatCfgDtlDTO, sysUlDatCfgDTO, picServicePath, audStsCdMap, voList);
				}
			}
        	
            return new ListPageVO<CapPayMaterialVo>(voList, voList.size());
        }
        return null;
	}
	
	private void setCapPayMaterialVo(SysUlDatCfgDtlDTO dtlDTO,SysUlDatCfgDTO dto,String picServicePath,Map<String, String> audStsCdMap,List<CapPayMaterialVo> voList) {
		CapPayMaterialVo vo = new CapPayMaterialVo();
		vo.setCfgDtlCd(dtlDTO.getCfgDtlCd());//配置子编号
		vo.setDatNm(dtlDTO.getDatNm());//配置名称
		vo.setCfgCd(dtlDTO.getCfgCd());//配置编号
		vo.setCfgNm(dto.getCfgNm());//配置子名称
		vo.setFileId(dtlDTO.getRecId());//附件ID
		//如果有HTTP开头说明是可以访问路径,无需干涉
		if(StringUtils.isNotBlank(dtlDTO.getFilePath())&&!dtlDTO.getFilePath().startsWith("http") && StringUtils.isNotBlank(picServicePath)){
			vo.setFilePath(picServicePath+dtlDTO.getFilePath());
		}else{
			vo.setFilePath(dtlDTO.getFilePath());//附件路径
		}
		vo.setFileNm(dtlDTO.getRecFileNm());//上传名称
		vo.setCrtTm(dtlDTO.getRecCrtTm());//上传时间
		vo.setOrgCd(dtlDTO.getOrgCd());//机构代码
		vo.setSysCd(dtlDTO.getSysCd());//系统代码
		//是否必传
		vo.setIsMust(dtlDTO.getIsMust());
		if (StringUtils.isNotBlank(dtlDTO.getRecAudStsCd())) {
			vo.setAudStsCd(dtlDTO.getRecAudStsCd());//验证状态
		} else {
			vo.setAudStsCd("0");//验证状态
		}

		if (audStsCdMap != null && audStsCdMap.containsKey(vo.getAudStsCd())) {
			vo.setAudStsCdNm(audStsCdMap.get(vo.getAudStsCd()));
		}
		voList.add(vo);
	}
	
	
	 /**
	  * 金融机构详情-备案资料（上传）
	  * @param request
	  * @param response
	  * @return
	  * @throws BaseException
	  */
    @RequestMapping(value = "/uploadRecordInfoFile.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object uploadRecordInfoFile(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_FILE_UPLOAD_SUCC);
        String fileParams = request.getParameter("fileParams");
        String cfgCd = request.getParameter("cfgCd");
        String cfgDtlCd = request.getParameter("cfgDtlCd");
        String friId = request.getParameter("friId");
        if (StringUtils.isBlank(friId)) {
            BaseLogUtils.error(logger, "uploadRecordInfoFile", "上传金融机构详情-备案资料失败,金融机构friId为空");
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_FILE_UPLOAD_FAIL);
        } else {
            boolean flag = false;
                flag = this.sysUlFilesRecService.addAttchmnt(friId, fileParams, cfgCd, cfgDtlCd, FriBaseInfoConstant.FLOW_BUSINESS_TYP_FUND_RAS_INS_BASE_INFO, null, null, null, false, FncPrjContMainConstant.ORG_CODE);
            if (!flag) {
                BaseLogUtils.error(logger, "", "上传资料文件失败==>friId=" + friId + ",cfgCd=" + cfgCd + ",cfgDtlCd=" + cfgDtlCd + ",file=" + fileParams );
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_FILE_UPLOAD_FAIL);
                return result;
            }
            BaseLogUtils.info(logger, "", "上传资料文件成功==>friId=" + friId + ",cfgCd=" + cfgCd + ",cfgDtlCd=" + cfgDtlCd );
        }
        return result;
    }
    /**
	 * 初始化列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/initRlPsnList.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object initRlPsnList(HttpServletRequest request, HttpServletResponse response) {
		String fundId = request.getParameter("fund_id");// 融资机构id
		if (StringUtils.isEmpty(fundId)) {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "融资机构id不能为空!");
		}
		// 查询主要联系人
		FundRasInsRlPsnQueryCondition psn = new FundRasInsRlPsnQueryCondition();
		psn.setFundId(Long.parseLong(fundId));
		List<FundRasInsRlPsnVO> rllistVo = FundRasInsRlPsnVOTransform
				.toVOList(fundRasInsRlPsnApiService.searchList(psn));
		this.setDic(rllistVo, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());// 设置数据字典
		ListPageVO<FundRasInsRlPsnVO> listPage = new ListPageVO<FundRasInsRlPsnVO>(rllistVo, rllistVo.size());
		BaseLogUtils.newServiceLogger("initRlPsnList===修改数据,rlList:" + JSON.toJSONString(listPage)).info();
		return listPage;
	}
	/**
	 * 融担数据上报功能 金融机构 主要人员信息     删除功能
	 * 
	 */
	@RequestMapping(value = "/updateRlPsnbyId.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object updateRlPsnbyId(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "成功!");
		// 获取数据
		String rl_psn_id = request.getParameter("rl_psn_id");//主要人员信息id
		if (StringUtils.isNotBlank(rl_psn_id)) {
		} else {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("业务主键不允许为空失败!");
			return result;
		}
		//获取联系人信息
		FundRasInsRlPsnQueryCondition rlPsnQc = new FundRasInsRlPsnQueryCondition();
		rlPsnQc.setId(Long.parseLong(rl_psn_id));
		List<FundRasInsRlPsnVO> rlPsnlist = FundRasInsRlPsnVOTransform.toVOList(fundRasInsRlPsnApiService.searchList(rlPsnQc));
		FundRasInsRlPsnVO rlPsnVO = new FundRasInsRlPsnVO();
		if(rlPsnlist!=null && rlPsnlist.size()>0) {
			rlPsnVO = rlPsnlist.get(0);
		}
		boolean isLink=false;//联系人提示信息
		boolean isFaMust=false;//法人代表提示信息
		//获取当前删掉的联系人类型是否包含 法人代表或者联系人类型
		String rlTypeCd=rlPsnVO.getRlTypCd();
		boolean isCon=false;//true包含 flase 不包含
		if(!rlTypeCd.isEmpty() && (rlTypeCd.indexOf("2")>=0 || rlTypeCd.indexOf("1")>=0)) {
			isCon=true;
		}
		if(isCon){//校验主要联系人，至少有一条联系人信息或者 命中类型，至少有法人代表信息
			//获取联系人信息list
			FundRasInsRlPsnQueryCondition rlPsnQcc = new FundRasInsRlPsnQueryCondition();
			rlPsnQcc.setFundId(rlPsnVO.getFundId());//金融机构id
			List<FundRasInsRlPsnVO> falist = FundRasInsRlPsnVOTransform.toVOList(fundRasInsRlPsnApiService.searchList(rlPsnQcc));
			BaseLogUtils.newServiceLogger("updateRlPsnbyId===修改数据,falist:" + JSON.toJSONString(falist)).info();
			if(falist!=null && falist.size()>0) {
				StringBuffer rlTypeCdstr= new StringBuffer();
				for(int k=0;k<falist.size();k++) {
					if(StringUtils.isNotBlank(falist.get(k).getRlTypCd())) {
						rlTypeCdstr.append(falist.get(k).getRlTypCd());
						String[] rlTypCdArray = falist.get(k).getRlTypCd().split(";");
						for (String tcpString : rlTypCdArray) {
							if (tcpString.indexOf("1")>=0) {
								if(!rl_psn_id.equals(String.valueOf(falist.get(k).getId()))) {
									isLink=true;
								}
							}
						}
 						//当结构类型命中：1-工商企业、2-银行 、3-小额贷款公司、4-事业单位情况下；法人代表姓名必填
						FriBaseInfoVO friVo = friBaseInfoService.selectById(rlPsnVO.getFundId(), CurrentThreadContext.getCurrentSysCd(),
								CurrentThreadContext.getCurrentOrgCd());
						if(StringUtils.isNotBlank(friVo.getFundInsType())) {
							String fundInsType=friVo.getFundInsType();
							if("1".equals(fundInsType) || "2".equals(fundInsType)
								|| "3".equals(fundInsType) || "4".equals(fundInsType)) {
								for (String tcpString : rlTypCdArray) {
									if (tcpString.indexOf("2")>=0) {
										if(!rl_psn_id.equals(String.valueOf(falist.get(k).getId()))) {
											isFaMust=true;
										}
									}
								}
							}else {
								isFaMust=true;
							}
						}//end 当结构类型命中
					}//end StringUtils.isNotBlank(falist.get(k).getRlTypCd())
				}//end for 循环
			}//end falist!=null && falist.size()>0
		}else{
			isLink=true;//联系人提示信息
			isFaMust=true;//法人代表提示信息
		}//end isCon
		
		if(!isFaMust) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("至少有一条法人代表人员信息，不允许删除!");
			return result;
		}
		if(!isLink) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("至少有一条联系人人员信息，不允许删除!");
			return result;
		}
		BaseLogUtils.newServiceLogger("updateRlPsnbyId===作废rl_psn_id:" + rl_psn_id).info();
		// 封装数据
		FundRasInsRlPsnVO rlPsn = new FundRasInsRlPsnVO();
		rlPsn.setId(Long.parseLong(rl_psn_id));
		rlPsn.setIsDel(BaseConstant.IS_YESNO_YES);
		rlPsn.setMdfTm(new Date());
		rlPsn.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		// 保存
		try {
			fundRasInsRlPsnApiService.modify(FundRasInsRlPsnVOTransform.toDTO(rlPsn));
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("操作成功!");
			BaseLogUtils.info(logger, "updateRlPsnbyId", "作废数据 , rl_psn_id:" + rl_psn_id, CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("操作失败!");
			BaseLogUtils.newServiceLogger("initRlPsnList===作废数据,rl_psn_id:" + rl_psn_id).error(LogExceptionEnum.DATA_CODE_0201);;
		}
		return result;
	}
	/**
	 * 设置数据字典 证件类型 联系人类型
	 * @param list
	 * @param sysCd
	 * @param orgCd
	 */
	public void setDic(List<FundRasInsRlPsnVO> list, String sysCd, String orgCd) {
		List<KeyValueVO> list2 = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.CODE_GRP_CERT_TYP_CD, sysCd,
				orgCd);
		Map<String, String> rlTypCdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, FriBaseInfoConstant.CODE_RL_TYP_CD);
		if (list != null && list.size() > 0) {
			for (FundRasInsRlPsnVO dto : list) {
				// 证件类型名称
				for (int i = 0; i < list2.size(); i++) {
					KeyValueVO kv = list2.get(i);
					if (kv.getKey().equals(dto.getCertTypCd())) {
						dto.setCertTypCdNm(kv.getValue());
						break;
					}
				}
				// 联系人类型名称
				if (StringUtils.isNotEmpty(dto.getRlTypCd())) {
					// 联系人类型
					String[] rlTypCdArray = dto.getRlTypCd().split(";");
					String rlTypCdNm = "";
					for (String tcpString : rlTypCdArray) {
						if (rlTypCdMap.containsKey(tcpString)) {
							rlTypCdNm += rlTypCdMap.get(tcpString);
							rlTypCdNm += ";";
						}
					}
					if (StringUtils.isNotEmpty(rlTypCdNm)) {
						rlTypCdNm = rlTypCdNm.substring(0,rlTypCdNm.length() - 1);
					}
					dto.setRlTypCdNm(rlTypCdNm);;
				}//end 联系人类型名称
				
			}
		}
	}
	/**
	   * 发起卓远担保新业务评审流程R024
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/addFlowStartForGuarantee.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addFlowStartForGuarantee(HttpServletRequest request, HttpServletResponse response) {

		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if (StringUtils.isEmpty(id)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "addFlowStartForGuarantee", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			// 流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(FriBaseInfoConstant.REF_FLOW_S_H_FRI);
			//flowStartParamsDTO.setProcDefKey(procDefKey);
			//flowStartParamsDTO.setProcDefId(procDefId);
			//flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setBusinessKey(id);
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);// 优先级,可以在界面定义
			//flowStartParamsDTO.setBusinessType(FriBaseInfoConstant.FLOW_BUSINESS_TYP_FUND_RAS_INS_BASE_INFO);// 确认用不用
			flowStartParamsDTO.setModelTyp(FriBaseInfoConstant.GUARANTEE_FLOW_MODEL_TYP);//();// 需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm() + "、卓远担保新业务评审流程大字段参数未定!");
			DataResultDTO dataResultDTO = this.friBaseInfoService.addFlowStartForGuarantee(flowStartParamsDTO);
			if (!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if(null!=dataResultDTO && null!=dataResultDTO.getData()){
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if(StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())){
	                result.setInfo("下一个节点操作人:"+flowStartedDTO.getNextOperUsrNames());
	            }else{
	                result.setInfo("流程发起成功");
	            }
			}
			
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "addFlowStartForGuarantee",
					"错误[BaseException],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" + e.getMessage(),
					CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addFlowStartForGuarantee",
					"错误[Exception],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" + e.getMessage(),
					CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		}
		return result;
	}
	/**
	 * 	金融机构 卓远担保新业务评审流程 附加信息页面
	 */
	@RequestMapping(value = "/tofundGuaranteeDetail.do", method = { RequestMethod.GET })
	public ModelAndView tofundGuaranteeDetail(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/fribaseinfo/fundGuaranteeDetail");
		String id = request.getParameter("id");
		view.addObject("id", id);
		BaseLogUtils.info(logger, "modifyDetailPage", "修改数据,friVo[" + id + "].",
				CurrentThreadContext.getCurrentUserName());
		BaseLogUtils.newServiceLogger("===修改数据,friVo:" + JSON.toJSONString(id)).info();
		// 金融机构类型
		List<KeyValueVO> fundInsTypeList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_INS_TYPE);
		view.addObject("fundInsTypeList", fundInsTypeList);
		// 金融机构属性
		List<KeyValueVO> fundInsPropList = friBaseInfoService.getKvList(FriBaseInfoConstant.FUND_INS_PROP);
		view.addObject("fundInsPropList", fundInsPropList);
		// 证件类型
		List<KeyValueVO> certTypCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.CODE_GRP_CERT_TYP_CD);
		;
		view.addObject("certTypCdListJSON", JSON.toJSON(certTypCdList));
		// 联系人类型
		List<KeyValueVO> rlTypCDList = friBaseInfoService.getKvList(FriBaseInfoConstant.CODE_RL_TYP_CD);
		view.addObject("rlTypCDListJSON", JSONObject.toJSONString(rlTypCDList));
		// 万元美元
		List<KeyValueVO> capUntCdList = friBaseInfoService.getKvList(FriBaseInfoConstant.CODE_GRP_REG_CAP_UNT_CD);
		view.addObject("capUntCdList", capUntCdList);
		FriBaseInfoVO vo = new FriBaseInfoVO();
		view.addObject("isRlpsn", 0);
		if (StringUtils.isNotBlank(id)) {
			vo = friBaseInfoService.selectById(Long.parseLong(id), CurrentThreadContext.CURRENT_SYS_CD,
					CurrentThreadContext.CURRENT_ORG_CD);
			//格式化注册时间 合作时间
			if(vo!=null) {
				if(vo.getRegCapTm()!=null) {
					vo.setRegCapTmStr(DateUtils.formatDateToString(vo.getRegCapTm(), DateUtils.YYYY_MM_DDHHMMSS));
				}
				if(vo.getCoopTm()!=null){
					vo.setCoopTmStr(DateUtils.formatDateToString(vo.getCoopTm(), DateUtils.YYYY_MM_DDHHMMSS));
				}
			}
			// 查询主要联系人
			FundRasInsRlPsnQueryCondition psn = new FundRasInsRlPsnQueryCondition();
			psn.setFundId(Long.parseLong(id));
			List<FundRasInsRlPsnVO> fundRasInsRlPsnVOs = FundRasInsRlPsnVOTransform
					.toVOList(fundRasInsRlPsnApiService.searchList(psn));
			vo.setFundRasInsRlPsnVOs(fundRasInsRlPsnVOs);
			view.addObject("friVo", vo);
			if(fundRasInsRlPsnVOs!=null && fundRasInsRlPsnVOs.size()>0) {
				view.addObject("isRlpsn", fundRasInsRlPsnVOs.size());
			}
		} else {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "金融机构id不能为空!");
		}
		BaseLogUtils.newServiceLogger("===修改数据,friVo:" + JSON.toJSONString(vo)).info();
		BaseLogUtils.info(logger, "modifyDetailPage", "修改数据,friVo[" + JSON.toJSONString(vo) + "].",
				CurrentThreadContext.getCurrentUserName());
		return view;
	}
		
		
}
